<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <!-- 引入EasyUI的CSS和JS -->
    <link rel="stylesheet" type="text/css"
          href="./themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="./themes/icon.css">
    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <script type="text/javascript" src="./js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="./js/download.js"></script>
    <script type="text/javascript" src="./js/jquery.serializejson.min.js"></script>
    <script type="text/javascript" src="./locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#dg')
                .datagrid(
                    {
                        url: '${pageContext.request.contextPath}/student_list.action',
                        toolbar: [{
                            iconCls: 'icon-edit',
                            handler: function () {
                                alert('编辑按钮')
                            }
                        }, '-', {
                            iconCls: 'icon-help',
                            handler: function () {
                                alert('帮助按钮')
                            }
                        }],
                        columns: [[
                            {
                                field: 'ck',
                                checkbox: true
                            },
                            {
                                field: 'studentNumber',
                                title: '学号',
                                width: 120,
                                align: 'center'
                            },
                            {
                                field: 'studentName',
                                title: '学生姓名',
                                width: 120,
                                align: 'center'
                            },
                            {
                                field: 'password',
                                title: '密码',
                                width: 150,
                                align: 'center'
                            },
                            {
                                field: 'year',
                                title: '学年',
                                width: 120,
                                align: 'center'
                            },
                            {
                                field: 'college',
                                title: '所属学院',
                                width: 180,
                                align: 'center'
                            },
                            {
                                field: 'major',
                                title: '所属专业',
                                width: 160,
                                align: 'center'
                            },
                            {
                                field: 'classAndGrade',
                                title: '班级',
                                width: 100,
                                align: 'center'
                            },
                            {
                                field: 'ptc',
                                title: '打卡次数',
                                width: 100,
                                align: 'center'
                            },
                            {
                                field: 'xxx',
                                title: '操作',
                                width: 160,
                                align: 'center',
                                formatter: function (value, row, index) {
//                                class='easyui-linkbutton' iconCls='icon-reload'
                                    return "<button href='#'  onclick='update("
                                        + row.sid
                                        + ")'>编辑</button>   &nbsp;&nbsp; | | &nbsp;&nbsp;  <button href='#' onclick='del("
                                        + row.sid + ")'>删除</button>";
                                }
                            }]],
                        rownumbers: true,
                        striped: true,
                        // 显示分页工具条
                        pagination: true,
                        // 分页条位置
                        pagePosition: "bottom",
                        // 初始化页数
                        pageNumber: 1,
                        // 每页显示多少条记录
                        pageSize: 16,
                        pageList: [16, 18, 20],
                        toolbar: [
                            {
                                text: '添加',
                                iconCls: 'icon-add',
                                handler: function () {
                                    $('#winAdd').window('open');
                                }
                            },
                            '-',
                            {
                                text: '导出',
                                iconCls: 'icon-edit',
                                handler: function () {
                                    var formData = $("#searchFrom")
                                        .serializeJSON();

                                    $.download(
                                            '${pageContext.request.contextPath}/student_export.action',
                                            formData);
                                }
                            }, '-', {
                                text: '导入',
                                iconCls: 'icon-edit',
                                handler: function () {
                                    $('#importDlg').dialog('open');

                                }
                            }]
                    });

        });

        //导入学生
        function submit2() {
            $.ajax({
                url: '${pageContext.request.contextPath}/student_doImport.action',
                data: new FormData($('#importForm')[0]),
                type: 'post',
                processData: false,
                contentType: false,
                dataType: 'json',
                success: function (rtn) {
                    $.messager.alert('提示', rtn.msg, 'info', function () {
                        $('#importDlg').window('close');
                        $('#importForm').form('clear');
                        $("#dg").datagrid("reload");
                    });
                }
            });
        }

        //查找学生
        function submit() {
            var formData = $("#searchFrom").serializeJSON();
            $.ajax({
                url: '${pageContext.request.contextPath}/student_list.action',
                data: formData,
                dataType: 'json',
                success: function (data) {
                    $('#dg').datagrid('loadData', data);
                }
            });
        }

        //修改学生

        function update(id) {
            $("#formUpdate").form('load', 'student_getById.action?sid=' + id);
            $('#winUpdate').window('open');
            // submit the form
            // $('#formUpdate').submit();
        }

        function update2() {
            $('#formUpdate').form('submit', {
                url: "student_saveOrUpdate.action",
                success: function (data) {
                    var jsonData = eval("(" + data + ")");
                    $.messager.show({
                        title: '提示消息',
                        msg: jsonData.msg,
                        timeout: 3000,
                        showType: 'slide'
                    });
                    // 关闭窗口:
                    $("#winUpdate").window("close");
                    // 重新加载数据:
                    $("#dg").datagrid("reload");
                }
            });
        }

        //保存学生
        function save() {
            // 提交数据到Action
            $('#formAdd').form('submit', {
                url: "student_saveOrUpdate.action",
                success: function (data) {
                    // data是字符串类型
                    // "alert('')"
                    var jsonData = eval("(" + data + ")");
                    $.messager.show({
                        title: '提示消息',
                        msg: jsonData.msg,
                        timeout: 3000,
                        showType: 'slide'
                    });

                    // 关闭窗口
                    $("#winAdd").window("close");
                    // 表格重新加载
                    $("#dg").datagrid("reload");
                }
            });
        }

        //删除学生
        function del(id) {
            $.messager
                .confirm(
                    '确认',
                    '您确认想要删除记录吗？',
                    function (r) {
                        if (r) {
                            $
                                .post(
                                    "${pageContext.request.contextPath}/student_delete.action",
                                    {
                                        "sid": id
                                    },
                                    function (data) {
                                        $.messager.show({
                                            title: '提示消息',
                                            msg: data.msg,
                                            timeout: 3000,
                                            showType: 'slide'
                                        });
                                        $("#dg").datagrid("reload");
                                    }, "json");
                        }
                    });

        }
    </script>
</head>
<body>

<div id="importDlg" class="easyui-window" style="padding: 4px;"
     data-options="modal:true,closed:true">
    <form id="importForm" enctype="multipart/form-data" method="post">
        <input type="file" name="file"/>
    </form>
    <button onclick="submit2()">提交</button>
</div>
<div style="float: left;">
    <form id="searchFrom" method="post">
        学号:<input name="studentNumber" style="WIDTH: 120px"/>
        学院:
        <select name="college" id="select5" onchange="selectCS3()" style="WIDTH: 160px">
            <option value="">------请选择------</option>
            <option value="中兴通讯信息学院">中兴通讯信息学院</option>
            <option value="经济与管理学院">经济与管理学院</option>
        </select>
        专业:
        <select id="select6" style="WIDTH: 120px" name="major"></select>
        班级:
        <select name="classAndGrade" style="WIDTH: 120px">
            <option value="">------请选择------</option>
            <option value="一班">一班</option>
            <option value="二班">二班</option>
        </select>
        学年:
        <select name="year" style="WIDTH: 120px">
            <option value="">------请选择------</option>
            <option value="16级">16级</option>
            <option value="17级">17级</option>
            <option value="18级">18级</option>
        </select>
        打卡情况:
        <select name="ptc" style="WIDTH: 120px">
            <option value="">------请选择------</option>
            <option value="1">成绩合格</option>
            <option value="0">成绩不合格</option>
        </select>

        <input type="reset" value="重置">
    </form>
</div>&nbsp;&nbsp;&nbsp;

<a class='easyui-linkbutton' iconCls='icon-search'  onclick="submit()">提交</a>
<table id="dg"></table>

<!-- 添加学生的表单，默认是隐藏的 -->
<div id="winAdd" class="easyui-window" title="添加学生"
     style="width: 600px; height: 200px"
     data-options="iconCls:'icon-save',modal:true,closed:true">

    <form id="formAdd" method="post">
        <TABLE cellSpacing=0 cellPadding=5 border=0>
            <TR>
                <td>学生姓名：</td>
                <td><INPUT class="textbox" style="WIDTH: 180px" maxLength=50
                           name="studentName"></td>
                <td>学号 ：</td>
                <td><INPUT id="sNumber" class="textbox" style="WIDTH: 180px" maxLength=50
                           name="studentNumber"></td>
            </TR>

            <TR>
                <td>学院 ：</td>
                <td>
                    <select id="select1" onchange="selectCS()" name="college" style="WIDTH: 180px">
                        <option value="">------请选择------</option>
                        <option value="中兴通讯信息学院">中兴通讯信息学院</option>
                        <option value="经济与管理学院">经济与管理学院</option>
                    </select>
                    <%--<INPUT class="textbox" style="WIDTH: 180px" maxLength=50 name="college">--%>
                </td>
                <td>专业：</td>
                <td>
                    <select id="select2" style="WIDTH: 180px" name="major"></select>
                </td>
            </TR>

            <!-- private Long sid;
              private String studentName;
              private String password;
              private String college;
              private String year;
              private String major;
              private String classAndGrade;
              private String studentNumber;
              private String ptc; -->

            <TR>
                <td>班级 ：</td>
                <td>
                    <%--<INPUT class="textbox" style="WIDTH: 180px" maxLength=50 name="classAndGrade">--%>
                    <select name="classAndGrade" style="WIDTH: 180px">
                        <option value="">------请选择------</option>
                        <option value="一班">一班</option>
                        <option value="二班">二班</option>
                    </select>
                </td>
                <td>密码 ：</td>
                <td><INPUT id="sPassword" class="textbox" style="WIDTH: 180px" maxLength=50
                           name="password"></td>

            </TR>

            <TR>
                <td>学年 ：</td>
                <td>
                    <select name="year" style="WIDTH: 180px">
                        <option value="">------请选择------</option>
                        <option value="16级">16级</option>
                        <option value="17级">17级</option>
                        <option value="18级">18级</option>
                    </select>
                </td>
                <td>打卡次数 ：</td>
                <td><INPUT class="textbox" style="WIDTH: 180px" maxLength=50
                           name="ptc"></td>
            </TR>

            <tr>
                <td rowspan=2>
                    <button id="customerBtn" type="button" onclick="save()">保存</button>
                </td>
            </tr>
        </TABLE>
    </form>
</div>


<!-- 修改学生的表单，默认是隐藏的 -->
<div id="winUpdate" class="easyui-window" title="修改学生"
     style="width: 600px; height: 200px"
     data-options="iconCls:'icon-save',modal:true,closed:true">

    <form id="formUpdate" method="post">
        <TABLE cellSpacing=0 cellPadding=5 border=0>
            <TR>
                <td>学生姓名：</td>
                <td><INPUT class="textbox" style="WIDTH: 180px" maxLength=50
                           name="studentName"></td>
                <td>密码 ：</td>
                <td><INPUT class="textbox" style="WIDTH: 180px" maxLength=50
                           name="password"></td>
            </TR>

            <TR>
                <td>学院 ：</td>
                <td>
                    <select name="college" id="select3" onchange="selectCS2()" class="textbox" style="WIDTH: 180px">
                        <option value="">------请选择------</option>
                        <option value="中兴通讯信息学院">中兴通讯信息学院</option>
                        <option value="经济与管理学院">经济与管理学院</option>
                    </select>
                </td>
                <td>专业：</td>
                <td>
                    <select name="major" id="select4" class="textbox" style="WIDTH: 180px">
                        <option value="通信工程">通信工程</option>
                        <option value="物联网">物联网</option>
                        <option value="电信">电信</option>
                    </select>
                </td>
            </TR>

            <!-- private Long sid;
              private String studentName;
              private String password;
              private String college;
              private String year;
              private String major;
              private String classAndGrade;
              private String studentNumber;
              private String ptc; -->

            <TR>
                <td>班级 ：</td>
                <td><select name="classAndGrade" class="textbox" style="WIDTH: 180px">
                    <option value="">------请选择------</option>
                    <option value="一班">一班</option>
                    <option value="二班">二班</option>
                </select></td>
                <td>学号 ：</td>
                <td><INPUT class="textbox" style="WIDTH: 180px" maxLength=50
                           name="studentNumber"></td>
            </TR>

            <TR>
                <td>学年 ：</td>
                <td>
                    <select name="year" class="textbox" style="WIDTH: 180px">
                        <option value="">------请选择------</option>
                        <option value="16级">16级</option>
                        <option value="17级">17级</option>
                        <option value="18级">18级</option>
                    </select>
                </td>
                <td>打卡次数 ：</td>
                <td><INPUT class="textbox" style="WIDTH: 180px" maxLength=50
                           name="ptc">
                </td>
            </TR>

            <TR>
                <td><INPUT type="hidden" class="textbox" style="WIDTH: 180px"
                           maxLength=50 name="sid">
                </td>
            </TR>

            <tr>
                <td rowspan=2>
                    <button id="customerBtn" type="button" onclick="update2()">更新</button>
                </td>
            </tr>
        </TABLE>
    </form>
</div>
<script>
    var classAndGrades = [
        ['通信工程', '物联网', '电信'],
        ['财务管理', '软件工程', '计算机网络']
        /*[9, 10, 11, 12],
        [13, 14, 15, 16]*/
    ];


    function selectCS() {
        var select1 = document.getElementById("select1");
        var select2 = document.getElementById("select2");
        //alert(select1.value);
        select2.length = 0;
        if (select1.value == '中兴通讯信息学院') {
            var value1 = 0;
        }
        if (select1.value == '经济与管理学院') {
            var value1 = 1;
        }
//        var value1 = select1.value;
        var majors = classAndGrades[value1];
        for (var i = 0; i < majors.length; i++) {
            var major = majors[i];
            var option1 = document.createElement("option");
            var textNode = document.createTextNode(major);
            option1.appendChild(textNode);
            select2.appendChild(option1);
        }
    }

    function selectCS2() {
        var select3 = document.getElementById("select3");
        var select4 = document.getElementById("select4");
        //alert(select1.value);
        select4.length = 0;
        if (select3.value == '中兴通讯信息学院') {
            var value1 = 0;
        }
        if (select3.value == '经济与管理学院') {
            var value1 = 1;
        }
//        var value1 = select1.value;
        var majors = classAndGrades[value1];
        for (var i = 0; i < majors.length; i++) {
            var major = majors[i];
            var option1 = document.createElement("option");
            var textNode = document.createTextNode(major);
            option1.appendChild(textNode);
            select4.appendChild(option1);
        }
    }

    $("#sNumber").keyup(function () {
        $("#sPassword").val($("#sNumber").val());
    })


    function selectCS3() {
        var select5 = document.getElementById("select5");
        var select6 = document.getElementById("select6");
        //alert(select1.value);
        select6.length = 0;
        if (select5.value == '中兴通讯信息学院') {
            var value1 = 0;
        }
        if (select5.value == '经济与管理学院') {
            var value1 = 1;
        }
//        var value1 = select1.value;
        var majors = classAndGrades[value1];
        for (var i = 0; i < majors.length; i++) {
            var major = majors[i];
            var option1 = document.createElement("option");
            var textNode = document.createTextNode(major);
            option1.appendChild(textNode);
            select6.appendChild(option1);
        }
    }

</script>
</body>
</html>